Using the {vtree} package to visualize discrete multivariate data (c) Nick Barrowman, Richard Webster 2022. Image credit: Ed323 at English Wikipedia, Public domain, via Wikimedia Commons

Instructors

Outline

Session 1: Introduction to vtree

A simple example

Dataset

https://www.frontiersin.org/articles/10.3389/fcomm.2021.789272/full

A Repeated Measures Dataset on Public Responses to the COVID-19 Pandemic: Social Norms, Attitudes, Behaviors, Conspiracy Thinking, and (Mis)Information by Eric Allen Jensen, Axel Pfleger, Lars Lorenz, Aaron Michael Jensen, Brady Wagoner, Meike Watzlawik, and Lisa Herbig

 

Data set is available at: https://zenodo.org/record/5779516

Read data and perform some pre-processing

library(vtree)
library(dplyr)
library(haven)
data <- read_spss("https://zenodo.org/record/5779516/files/Viral_Communication_Phase_I-III.sav")

d <- as_factor(data)
agreement <- function(x,neutralAgree=TRUE,agree="Agree",disagree="Disagree") {
  neutral <- if (neutralAgree) agree else disagree
  case_when(
    {{x}} == "Strongly Agree"    ~ agree,
    {{x}} == "Agree"             ~ agree,
    {{x}} == "Somewhat Agree"    ~ agree,
    {{x}} == "Neutral"           ~ neutral,
    {{x}} == "Somewhat Disagree" ~ disagree,
    {{x}} == "Disagree"          ~ disagree,
    {{x}} == "Strongly Disagree" ~ disagree)
}
d <- d %>%
  mutate(
    Phase_1=M_PHASE1_COMPETION,
    Phase_2=M_PHASE2_COMPLETION,
    Phase_3=M_PHASE3_COMPLETION,
    politics_1=factor(case_when(
      SD_POL_ORIENTATION == "Left"   ~ "Left",
      SD_POL_ORIENTATION == "-2"     ~ "Left",
      SD_POL_ORIENTATION == "-1"     ~ "Left",
      SD_POL_ORIENTATION == "Centre" ~ "Centre",
      SD_POL_ORIENTATION == "1"      ~ "Right",
      SD_POL_ORIENTATION == "2"      ~ "Right",
      SD_POL_ORIENTATION == "Right"  ~ "Right"),levels=c("Left","Centre","Right")),
    mask_1=case_when(
      PHASE1_AC_EFF_MASK == "Extremely effective"            ~ "Effective",
      PHASE1_AC_EFF_MASK == "Very effective"                 ~ "Effective",
      PHASE1_AC_EFF_MASK == "Effective"                      ~ "Effective",
      PHASE1_AC_EFF_MASK == "Somewhat effective"             ~ "Less effective",
      PHASE1_AC_EFF_MASK == "Not effective at all effective" ~ "Less effective"),
    world_1=agreement(PHASE1_AS_WORLD,neutralAgree=TRUE),
    science_eb_1=case_when(
      PHASE1_AS_BOR_EXC == "Exciting" ~ "Exciting",
      PHASE1_AS_BOR_EXC == "2"        ~ "Exciting",
      PHASE1_AS_BOR_EXC == "1"        ~ "Exciting",
      PHASE1_AS_BOR_EXC == "0"        ~ "Not Exciting",
      PHASE1_AS_BOR_EXC == "-1"       ~ "Not Exciting",
      PHASE1_AS_BOR_EXC == "-2"       ~ "Not Exciting",
      PHASE1_AS_BOR_EXC == "Boring"   ~ "Not Exciting"),
    harmless_1=agreement(PHASE1_RA_HARMLESS_r,neutralAgree=TRUE,
      agree="Harmless",disagree="Not Harmless"),
    finance_1=agreement(PHASE1_RA_FINANCE,neutralAgree=FALSE),
    economy_1=agreement(PHASE1_RA_ECONOMY,neutralAgree=FALSE))
u <- d %>% filter(M_PHASE1_COMPETION=="Yes")
lv <- c(
  science_eb_1="Science is",
  harmless_1="Covid is",
  world_1="Science is making the world a better place")

Completed study phases

vtree(d,"Phase_1 Phase_2 Phase_3")

Completed study phases

Practical 1: Using vtree to examine a dataset

Some variables to try  
science_eb_1 I think science is boring
politics_1 Political orientation
SD_GENDER Gender
finance_1 I’m concerned about my financial situation
economy_1 I’m concerned about damage to the economy
harmless_1 I think Covid is harmless

10-minute break

Session 2: vtree features

Practical 2: Using vtree to make reproducible study flow diagrams

10-minute break

Wrap-up